package com.cyp.school.service.impl;

import com.cyp.school.dto.Result;
import com.cyp.school.entity.Comment;
import com.cyp.school.mapper.CommentMapper;
import com.cyp.school.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    
    @Resource
    private CommentMapper commentMapper;
    
    @Override
    public Result<Comment> addComment(Comment comment) {
        commentMapper.insert(comment);
        return Result.success(comment);
    }
    
    @Override
    public Result<List<Comment>> getCommentsByBlogId(Integer blogId) {
        List<Comment> comments = commentMapper.findByBlogId(blogId);
        return Result.success(comments);
    }
    
    @Override
    public Result<Boolean> deleteComment(Integer id) {
        commentMapper.deleteById(id);
        return Result.success(true);
    }
    
    @Override
    public Result<Integer> getCommentCount(Integer blogId) {
        int count = commentMapper.countByBlogId(blogId);
        return Result.success(count);
    }
} 